﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;

using System.ServiceModel.Description;
using System.Collections.ObjectModel;

using System.Xml;
using System.IO;
namespace hostwcf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1_Load);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            //FileStream file = new FileStream("Configuration.xml", FileMode.Create);
            //XmlTextWriter xml = new XmlTextWriter(file ,Encoding.Unicode);
            //xml.WriteStartDocument();
            //xml.WriteStartElement("config");
            ////xml.WriteStartAttribute("vanhung1");
            ////xml.WriteString("vanhung1");
            ////xml.WriteEndAttribute();
            //// xml.WriteString("nguyen van hung dai hoc bach khoa ha noi");
            //xml.WriteStartElement("user");
            //xml.WriteString("sa;");
            //xml.WriteEndElement();

            //xml.WriteStartElement("database");
            //xml.WriteString("vanhung;");
            //xml.WriteEndElement();
            //xml.WriteStartElement("password");
            //xml.WriteString("vanhung");
            //xml.WriteEndElement();
            //xml.WriteStartElement("datasource");
            //xml.WriteString(@"vanhung-pc\sqlexpress;");
            //xml.WriteEndElement();
            //xml.WriteEndElement();
            //xml.WriteEndDocument();
            //xml.Close();
            //file.Close();
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            Uri adress=new Uri("http://localhost:8011/vanhung");
       //     //Uri adress1 = new Uri("http://192.168.1.5:8011/vanhung.service");
            
            ServiceHost host = new ServiceHost(typeof(WcfServiceLibrary2.Service1));
       //     BasicHttpBinding binding = new BasicHttpBinding();
            
       //     binding.TransferMode = TransferMode.Streamed;
       //     binding.MaxBufferPoolSize = 2147483647;
       //     binding.MaxBufferSize = 2147483647;
       //     ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
       //     binding.MaxReceivedMessageSize = 2147483647;
       //     binding.MaxBufferSize=2147483647;
       //     binding.ReaderQuotas.MaxArrayLength = 2147483647;
       //     binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
       //     binding.ReaderQuotas.MaxStringContentLength = 2147483647;
       //     binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
            
       //     //binding.MessageEncoding = WSMessageEncoding.Mtom;
       //     //System.ServiceModel.
       //     binding.SendTimeout = new TimeSpan(1, 1, 1);
       //     binding.ReceiveTimeout = new TimeSpan(1, 1, 1);
       //     binding.TransferMode = TransferMode.Streamed;
       ////     maxReceivedMessageSize="2147483647"
       ////maxBufferSize="2147483647"
       //     behavior.HttpGetEnabled = true;
       //     behavior.ExternalMetadataLocation = adress;
       //    // behavior.HttpGetUrl=true;
       //     host.Description.Behaviors.Add(behavior);
       //     host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
       //     host.AddServiceEndpoint(typeof(WcfServiceLibrary2.IService1), binding, adress);
            host.Open();
            if (host.State==CommunicationState.Opened)
            {
                label1.Text = "openned";
              //  SinhVien.Run();
               // LopHoc.GetAllLopHoc();
            }
        }
    }
}
